package com.example.service.impl;

import com.example.entity.LowCodeMapping;
import com.example.mapp.LowCodeMappingMapp;
import com.example.service.LowCodeMappingSerive;
import com.example.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LowCodeMappingSeriveImpl implements LowCodeMappingSerive {
    private final static Logger logger = LoggerFactory.getLogger(LowCodeMappingSeriveImpl.class);


    @Autowired
    private LowCodeMappingMapp lowCodeMappingMapp;

    @Override
    public Map<String, Object> queryAll() {
        Map<String,Object> resultMap = new HashMap<>();
        try{
            List<LowCodeMapping> list = lowCodeMappingMapp.queryAll();
            resultMap.put("list",list);
            resultMap.put("total",list.size());
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",resultMap);
    }

    @Override
    public Map<String, Object> queryByCode(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        List<String> codes = (List<String>) map.get("codes");
        try{
            List<LowCodeMapping> list = lowCodeMappingMapp.queryByCode(codes);
            resultMap.put("list",list);
            resultMap.put("total",list.size());
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",resultMap);
    }
}
